#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: util_func.py 
@version:
@time: 2022/05/12 
"""
import copy


# get source db info
def get_generate_db_info(data):
    return data.get('generateTable').get('db_info')


# case data get
def get_case_data(data, dag):
    return data.get('generateCase').get(dag)


# case data get generateCase
def get_case(data: list):
    case = {}
    for one_data in data:
        case.update(one_data.get('generateCase'))
    return case


# table generate get
def get_generate_data(data):
    return data.get('generateTable')


# 是否使用并行流程
def use_parallel(data, signal):
    if signal:
        data['parallel_use_record_name'] = signal
    else:
        data['parallel_use_record_name'] = None
    return data


# 更新 setting
def task_update_setting(data, update):
    data['task_config']['config'].update(update)
    return data


# 更新任务名称
def task_update_dataflow_name(data, prefix='', suffix=''):
    name = data.get('task_config').get('config').get('name')
    new_name = f'{prefix}{name}{suffix}'
    data['task_config']['config'].update({'name': new_name})
    return copy.deepcopy(data)


# 更新ddl
def task_update_ddl(data, ddl_update):
    data['task_config']['config'].update({'ddl': ddl_update})
    return data


# 更新redis配置
def task_update_redis(data, redis_update):
    data['task_config']['config'].update({'redis': redis_update})
    return data


# 更新target info
def task_update_target_info(data, update_target_info):
    data['operate']['target']['target_info'].update(update_target_info)
    return data


# 更新 relation
def task_update_relation(data, update):
    data['task_config']['relationship'].update(update)
    return data


# 更新 dag种类
def task_update(data, update):
    # 用于案例数据更新
    # prefix， suffix 表前缀和后缀

    data.update(update)
    return data


# 更新stats
def task_stats_update(data, update):
    data['operate']['stats_check'].update(update)
    return data


# 更新source
def task_operate_update(data, update):
    data['operate'].update(update)
    return data
